* (bug 1962) Allow HTML attributes on <math>
* (bug 10530) Introduce optional "sp-contributions-explain" message for
additional explanation in Special:Contributions
+* (bug 10520) Preview licences during upload via AJAX (toggle with
+ $wgAjaxLicencePreview)
== Bugfixes since 1.10 ==
* to ensure that client-side caches don't keep obsolete copies of global
* styles.
*/
-$wgStyleVersion = '82';
+$wgStyleVersion = '83';
# Server-side caching:
*/
$wgAjaxUploadDestCheck = true;
+/**
+ * Enable previewing licences via AJAX
+ */
+$wgAjaxLicencePreview = true;
+
/**
* Allow DISPLAYTITLE to change title display
*/
function wfScript( $script = 'index' ) {
global $wgScriptPath, $wgScriptExtension;
return "{$wgScriptPath}/{$script}{$wgScriptExtension}";
+}
+
+/**
+ * Convenience function converts boolean values into "true"
+ * or "false" (string) values
+ *
+ * @param bool $value
+ * @return string
+ */
+function wfBoolToStr( $value ) {
+ return $value ? 'true' : 'false';
}
\ No newline at end of file
if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
+if( $wgAjaxLicencePreview )
+ $wgAjaxExportList[] = 'UploadForm::ajaxGetLicencePreview';
wfSeedRandom();
}
return $s;
}
+
+ /**
+ * Render a preview of a given licence for the AJAX preview on upload
+ *
+ * @param string $licence
+ * @return string
+ */
+ public static function ajaxGetLicencePreview( $licence ) {
+ global $wgParser;
+ $licence = self::getLicenceTitle( $licence );
+ if( $licence instanceof Title && $licence->exists() ) {
+ $title = SpecialPage::getTitleFor( 'Upload' );
+ $revision = Revision::newFromTitle( $licence );
+ $output = $wgParser->parse( $revision->getText(), $title, new ParserOptions() );
+ return $output->getText();
+ }
+ return '';
+ }
+
+ /**
+ * Get the title of the page associated with a given licence
+ * string, i.e. do a quick resolution of {{$license}} without
+ * invoking the full parser
+ *
+ * @param string $licence
+ * @return Title
+ */
+ private static function getLicenceTitle( $licence ) {
+ $template = substr( $licence, 0, 1 ) != ':';
+ $title = Title::newFromText( ltrim( $licence, ':' ) );
+ if( $title instanceof Title && $title->getNamespace() == NS_MAIN ) {
+ return $template
+ ? Title::makeTitle( NS_TEMPLATE, $title->getText() )
+ : $title;
+ }
+ return $title;
+ }
/**
* Stash a file in a temporary directory for later processing
*/
function mainUploadForm( $msg='' ) {
global $wgOut, $wgUser;
- global $wgUseCopyrightUpload, $wgAjaxUploadDestCheck, $wgUseAjax;
+ global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicencePreview;
global $wgRequest, $wgAllowCopyUploads, $wgEnableAPI;
- global $wgStylePath;
-
- $useAjax = $wgAjaxUploadDestCheck && $wgUseAjax;
+ global $wgStylePath, $wgStyleVersion;
- $wgOut->addScript(
- "<script type='text/javascript'>wgAjaxUploadDestCheck = " .
- ($useAjax ? 'true' : 'false' ) . ";</script>\n" .
- "<script type='text/javascript' src=\"$wgStylePath/common/upload.js?1\"></script>\n"
- );
+ $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
+ $useAjaxLicencePreview = $wgUseAjax && $wgAjaxLicencePreview;
+
+ $adc = wfBoolToStr( $useAjaxDestCheck );
+ $alp = wfBoolToStr( $useAjaxLicencePreview );
+
+ $wgOut->addScript( "<script type=\"text/javascript\">
+wgAjaxUploadDestCheck = {$adc};
+wgAjaxLicencePreview = {$alp};
+</script>
+<script type=\"text/javascript\" src=\"{$wgStylePath}/common/upload.js?{$wgStyleVersion}\"></script>
+ " );
if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
{
"size='40' />" .
"<input type='hidden' name='wpSourceType' value='file' />" ;
}
- if ( $useAjax ) {
+ if ( $useAjaxDestCheck ) {
$warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>";
$destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"';
} else {
</select>
</td>
</tr>
- <tr>
- ");
+ <tr>" );
+ if( $useAjaxLicencePreview ) {
+ $wgOut->addHtml( "
+ <td id=\"mw-licence-preview\" colspan=\"2\"></td>
+ </tr>
+ <tr>" );
+ }
}
if ( $wgUseCopyrightUpload ) {
function licenseSelectorCheck() {
- var selector = document.getElementById("wpLicense");
- if (selector.selectedIndex > 0 &&
- selector.options[selector.selectedIndex].value == "" ) {
- // Browser is broken, doesn't respect disabled attribute on <option>
- selector.selectedIndex = 0;
+ var selector = document.getElementById( "wpLicense" );
+ if( selector.selectedIndex > 0 ) {
+ var selection = selector.options[selector.selectedIndex].value;
+ if( selection == "" ) {
+ // Option disabled, but browser is broken and doesn't respect this
+ selector.selectedIndex = 0;
+ } else {
+ // We might show a preview
+ if( wgAjaxLicencePreview ) {
+ wgUploadLicenceObj.fetchPreview( selection );
+ }
+ }
}
}
}
}
-addOnloadHook(licenseSelectorFixup);
+var wgUploadLicenceObj = {
+
+ 'responseCache' : { '' : '' },
+
+ 'fetchPreview': function( licence ) {
+ if( licence in this.responseCache ) {
+ this.showPreview( this.responseCache[licence] );
+ } else {
+ sajax_do_call( 'UploadForm::ajaxGetLicencePreview', [licence],
+ function( result ) {
+ wgUploadLicenceObj.processResult( result, licence );
+ }
+ );
+ }
+ },
+
+ 'processResult' : function( result, licence ) {
+ this.showPreview( result.responseText );
+ this.responseCache[licence] = result.responseText;
+ },
+
+ 'showPreview' : function( preview ) {
+ var previewPanel = document.getElementById( 'mw-licence-preview' );
+ if( previewPanel.innerHTML != preview ) {
+ previewPanel.innerHTML = preview;
+ }
+ }
+
+}
+
+addOnloadHook( licenseSelectorFixup );
\ No newline at end of file